#ifndef __YX020_APP_H
#define __YX020_APP_H

#include "stdint.h"

#define YX020APP_CHIP_VERSION_BACK
// #define YX020APP_CHIP_VERSION_ABB

#if defined(YX020APP_CHIP_VERSION_BACK)
	#define YX020APP_CHIP_NUM		30
#elif defined(YX020APP_CHIP_VERSION_ABB)
	#define YX020APP_GROUP_NUM		15
	#define YX020APP_CHIP_N_EACH_G	2
#else
	#error "Undefine any chip version"
#endif

#define YX020APP_GC_5MA			0x00
#define YX020APP_GC_9MA			0x01
#define YX020APP_GC_13MA		0x02
#define YX020APP_GC_17_5MA		0x03

#define YX020APP_8BIT_EN		0x04
#define YX020APP_8BIT_UNEN		0x00

#define YX020APP_ISR_FAST		0x00
#define YX020APP_ISR_SLOW		0x08

#define YX020APP_FAULT_RM_EN	0x10
#define YX020APP_FAULT_RM_UNEN	0x00

#define YX020APP_ANALOG_EN		0x20
#define YX020APP_ANALOG_UNEN	0x00

#define YX020APP_PULSE_SMALL	0x40
#define YX020APP_PULSE_BIG		0x00

#define YX020APP_WATCH_DOG_EN	0x80
#define YX020APP_WATCH_DOG_UNEN	0x00

#if defined(YX020APP_CHIP_VERSION_ABB)
	#define YX020APP_BUF_NUM	0x01
#endif

#define YX020APP_IO_FORWAD		0x00
#define YX020APP_IO_REVERSE		0x40

#define YX020APP_BOARD_FORWAD	0x00
#define YX020APP_BOARD_REVERSE	0x80

#define YX020APP_VIN_DAMP_EN	0x01
#define YX020APP_VIN_DAMP_UNEN	0x00

#define YX020APP_UPDATE_CLEAR	0x00
#define YX020APP_UPDATE_CONTI	0x02

#define YX020APP_LSD_GEAR_0		0x00
#define YX020APP_LSD_GEAR_1		0x04
#define YX020APP_LSD_GEAR_2		0x08
#define YX020APP_LSD_GEAR_3		0x0C

#define YX020APP_LAST_FORW_EN	0x10
#define YX020APP_LAST_FORW_UNEN	0x00

typedef enum {
	YX020_DEMO_ALL_GREEN,
	YX020_DEMO_ALL_RED,
	YX020_DEMO_ALL_BLUE,
	YX020_DEMO_ALL_WHITE,
} YX020DemoModeEnum;

typedef struct {
	uint8_t gc;
	uint8_t bit8mode;
	uint8_t isr;
	uint8_t fault;
	uint8_t analog;
	uint8_t pulse;
	uint8_t watchdog;
	
	uint8_t dcGreen;
	uint8_t dcRed;
	uint8_t dcBlue;
	
#if defined(YX020APP_CHIP_VERSION_ABB)
	uint8_t chipNEachG;
	uint8_t bufNum;
#endif
	uint8_t ioDirection;
	uint8_t boardDirection;
	
	uint8_t vinDamp;
	uint8_t updateMode;
	uint8_t lsdGear;
	uint8_t lastForward;
} YX020APPRegInitTypedef;

typedef struct {
	uint16_t green;
	uint16_t red;
	uint16_t blue;
} YX020APPRGBTypedef;

void YX020APPInit(void);
void YX020APPGenREGVal(uint8_t *regs, YX020APPRegInitTypedef *regInit);
void YX020APPTask(void *parameter);

#endif
